<template>
	<div>
		<cl-crud @load="onLoad">
			<template #slot-datepicker>
				<div style="margin-left:1em">
					<date-picker
						@change="val => refresh({ startTime: val[0], endTime: val[1], page: 1 })"
						@refresh="refresh({ startTime: '', endTime: '', page: 1 })"
					></date-picker>
				</div>
			</template>

			<!-- 筛选 -->
			<template #slot-filter>
				<div class="filter-box">
					<el-select
						size="mini"
						filterable
						v-model="select.filters"
						placeholder="全部"
						style="margin-right: 10px;width:125px;margin-left:10px"
						@change="val => crud.refresh({ type: val })"
					>
						<el-option label="全部"></el-option>
						<el-option label="签到" :value="0"></el-option>
						<el-option label="每日任务" :value="1"></el-option>
						<el-option label="首次任务" :value="2"></el-option>
						<el-option label="长期任务" :value="3"></el-option>
					</el-select>
				</div>
			</template>

			<template #table-column-key="{scope}">
				<el-tag type="success">{{ scope.row.key }}</el-tag>
			</template>

			<template #table-column-type="{scope}">
				<el-tag v-if="scope.row.type == 0">签到</el-tag>
				<el-tag v-else-if="scope.row.type == 1">每日任务</el-tag>
				<el-tag v-else-if="scope.row.type == 2">首次任务</el-tag>
				<el-tag v-else-if="scope.row.type == 3">长期任务</el-tag>
			</template>

			<template #table-column-createTime="{scope}">
				<span>{{ toStamp(scope.row.createTime) }}</span>
			</template>

			<cl-form ref="cl-form"></cl-form>
		</cl-crud>
	</div>
</template>

<script>
import platform from '@/mixin/platform';
import DatePicker from '@/components/common/date-picker';
import moment from 'moment';

export default {
	data() {
		return {
			crud: null,
			options: [],
			select: {
				filters: ''
			}
		};
	},
	components: {
		DatePicker
	},
	mixins: [platform],
	methods: {
		toStamp(stamp) {
			return moment(stamp).format('YYYY-MM-DD HH:mm:ss');
		},
		onLoad({ ctx, app }) {
			this.crud = app;
			ctx.service(this.$service.integralMall.scoreMoneyList)
				.set('dict', {
					label: {
						add: '添加任务'
					},
					api: {
						page: 'scoreDetail'
					}
				})
				.set('table', {
					columns: [
						{
							label: '序号',
							type: 'index',
							align: 'center',
							width: 60
						},
						{
							label: '用户名',
							prop: 'nickName',
							align: 'center'
						},
						{
							label: '手机号',
							prop: 'phone',
							align: 'center'
						},
						{
							label: '积分',
							prop: 'score',
							align: 'center'
						},
						{
							label: '任务类型',
							prop: 'type',
							align: 'center'
						},
						{
							label: '备注',
							prop: 'remark',
							align: 'center'
						},
						{
							label: '创建时间',
							prop: 'createTime',
							align: 'center'
						}
					],
					op: {
						visible: false
					}
				})
				.set('layout', [
					['refresh-btn', 'slot-datepicker', 'slot-filter', 'flex1', 'search-key'],
					['data-table'],
					['flex1', 'pagination']
				])
				.done();

			app.refresh();
		},
		refresh(params) {
			this.crud.refresh(params);
		}
	}
};
</script>
